# -*- coding: utf-8 -*-
import unittest
import os, sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)
from api.base_api.login_base_api import LoginBaseApi
from api.base_api.modify_password_api import ModifyPassword
from fixture import user
from api.base_api.login_api import LoginApi
class ModifyPasswordTest(LoginBaseApi):
    ''' 测试修改密码 '''

    def setUp(self):
        self.mobile = '13900000000'
        self.oldPassword = '123abc'
        self.password = '456abc'
        self.modify_password_url = "http://192.168.1.141:8001/modify-password"

    def tearDown(self):
        user.update_user_password(self.mobile)

    def test_user_modify_success(self):
        ''' 修改成功 '''

        hander = LoginBaseApi().login_base_api(self.mobile, self.oldPassword)
        payload = ModifyPassword().modify_password(self.oldPassword, self.password)
        response = self.post(self.modify_password_url, payload, hander)
        status_code = response.status_code
        self.assertEqual(status_code, 200)

        #新密码登录
        success_status_code = LoginApi().login(self.mobile, self.password).status_code
        self.assertEqual(success_status_code, 200)
        #旧密码登录
        modify_fail_status_code = LoginApi().login(self.mobile, self.oldPassword).status_code
        self.assertNotEqual(modify_fail_status_code, 200)


if __name__ == '__main__':

    unittest.main()
